import com.sun.tools.classfile.CharacterRangeTable_attribute;

import java.util.HashMap;

public class ExcelSheetColName {
    public static int titleToNumber(String s) {
        HashMap<Character, Integer> valueDict = new HashMap<>();
        initDict(valueDict);
        int res = 0;
        for (int i = s.length() - 1; i >= 0; i--) {
            res += (int) Math.pow(26, s.length() - 1 - i) * valueDict.get(s.charAt(i));
        }
        return res;
    }

    public static void initDict(HashMap<Character, Integer> valueDict) {
        char[] keys = new char[]{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L'
                , 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
        for (int i = 0; i < keys.length; i++) {
            valueDict.put(keys[i], i + 1);
        }
    }

    public static void main(String[] args) {
        System.out.println(titleToNumber("AB"));
//        System.out.println((int)Math.pow(2,3));
    }
}
